version 13.0
log using "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\figure6.log", replace
#delimit ;

*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:      figure6.do                                      *;
*       Date:           January 14, 2019                                *;
*       Author:         MRG/CC                                          *;
*       Purpose:      	Produce Figure 6 for It's Not Only What You     *;
*                       Say, It's Also How You Say It: The Strategic    *;
*                       Use Of Campaign Sentiment. Journal of Politics. *;
*                       Forthcoming.                                    *;
* 	    Input File:     sentiment.dta                                   *;
*       Output File:    figure6.log                                     *;
*       Data Output:    none                                            *;             
*       Previous file:  sentiment.dta                                   *;
*       Machine:        desktop/laptop                     				*;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*        Load data                                                      *;
*     ****************************************************************  *;

use "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\sentiment.dta", clear;

set more off;

*     ****************************************************************  *;
*       Declare data to be panel, where the panel is based on language  *;
*     ****************************************************************  *;

xtset language;

xtsum positive_sentiment;

*     ****************************************************************  *;
*       Generate additional variables that we will need for our         *;
*       analysis.                                                       *;
*     ****************************************************************  *;

gen incumbent_inflation_l = incumbent*inflation_l;
label var incumbent_inflation "incumbent*inflation_l";
gen incumbent_unemployment_l = incumbent*unemployment_l;
label var incumbent_unemployment_l "incumbent*unemployment_l";
gen incumbent_pm = incumbent*pm;
label var incumbent_pm "incumbent*pm";
gen incumbent_fm = incumbent*fm;
label var incumbent_fm "incumbent*fm";
gen left_right2=left_right*left_right;
label var left_right2 "left_right*left_right";
gen extremist = 0;
replace extremist=1 if family_id ==14 | family_id==40;
replace extremist = . if family_id==.;
label var extremist "1 if communist/socialist or far right, 0 otherwise";
gen extremist2 = 0;
replace extremist2=1 if family_id ==14 | family_id==40 | family_id==19;
replace extremist2 = . if family_id==.;
label var extremist2 "1 if communist/socialist, far right, or greens, 0 otherwise";
gen extremist_inflation_l=extremist*inflation_l;
label var extremist_inflation "extremist*inflation_l";
gen extremist_unemployment_l=extremist*unemployment_l;
label var extremist_unemployment_l "extremist*unemployment_l";

tabulate language, gen(l);

*     ****************************************************************  *;
*      Change graph scheme	                                            *;
*     ****************************************************************  *;

*ssc install scheme-burd, replace;

*     ****************************************************************  *;
*     ****************************************************************  *;
*       Produce Figure 6                                                *;
*     ****************************************************************  *;
*     ****************************************************************  *;

set obs 10000;

bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent inflation_l incumbent_pm incumbent_inflation_l extremist, fe;


matrix b=e(b);
matrix V=e(V);

scalar b1=b[1,1];
scalar b3=b[1,3];
scalar b4=b[1,4];
scalar varb1=V[1,1];
scalar varb3=V[3,3];
scalar varb4=V[4,4];

scalar covb1b3=V[1,3];
scalar covb1b4=V[1,4];

scalar list b1 b3 b4 varb1 varb3 varb4 covb1b3 covb1b4;

vce;

generate MV=(_n-100)/100;

replace MV=. if _n>3000;

gen conbx=b1+b3+b4*MV if _n<3000;

gen consx=sqrt(varb1+varb3*1+varb4*(MV^2)+2*covb1b3+2*MV*covb1b4) if _n<3000;

gen ax=1.96*consx;

gen upperx=conbx+ax;

gen lowerx=conbx-ax;

graph twoway hist inflation_l, percent color(gs13) lcolor(white) yaxis(2) 
    || line upperx MV, color(ebblue) clpattern(longdash) 
    || line lowerx MV, color(ebblue) clpattern(longdash)  
    || line conbx MV,color(black) lwidth(medthick) legend(off) clpattern(solid)   
    ytitle("Effect of Incumbency on Positive Sentiment", size(2.5)) 
    title("", size(3)) subtitle("", size(3)) xtitle("Inflation", size(2.5)) 
    xscale(titlegap(4)) yscale(titlegap(4)) 
    || function y = 0, range(-1 29) clpatter(shortdash) color(black) 
    ||, xlabel(0 5 10 15 20 25 30, tlcolor(black) labcolor(black) labsize(2)) 
    ylabel(-0.5 0 0.5 1 1.5 2.0, tlcolor(black) labcolor(black) axis(1) labsize(2)) 
    ylabel(0 5 10 15 20 25 30 35,  axis(2) tlcolor(gs13) labcolor(gs13) labsize(2)) 
    yscale(noline alt) yscale(noline alt axis(2)) xscale(noline) legend(off) 
    ytitle("Percentage of Inflation Observations", color(gs12) axis(2) size(2.5)) 
    xsca(titlegap(2)) ysca(titlegap(2)) scheme(burd);
        
graph export "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig6.pdf", replace;
    
*     ****************************************************************  *;
*       Replication complete                                            *;
*     ****************************************************************  *;

log close;

clear;






